<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var findPoisonedDuration = function (timeSeries, duration) {
      let min = 0;
      let time = 0;
      for (let i = 0; i < timeSeries.length - 1; i++) {
        min = timeSeries[i + 1] - timeSeries[i];
        console.log(min)
        if (min >= duration)
          time += duration;
        else
          time += min;
      }
      time += duration;
      return time;
    };
    console.log(findPoisonedDuration(timeSeries = [1, 2], duration = 2))
  </script>
</body>

</html>